import Vue from 'vue'
import VueRouter from 'vue-router'
Vue.use(VueRouter)

const routes = [
  {
    path: '/login',
    name: 'Login',
    component: () => import('@/views/login.vue')
  },
  {
    path: '/',
    name: 'Layout',
    redirect: '/login',
    component: () => import('@/views/layout.vue'),
    children: [
      {
        path: '/home',
        name: 'Home',
        component: () => import('@/views/home/home.vue')
      },{
        path: '/baseinfo',
        name: 'BaseInfo',
        component: () => import('@/views/home/baseinfo.vue')
      },
      {
        path:'/analyseweight',
        name:'/AnalyseWeight',
        component: () => import('@/views/record/analyse_weight.vue')
      },
      {
        path:'/foodrecoreded',
        name:'/FoodRecoreded',
        component: () => import('@/views/record/food_recoreded.vue')
      },
      {
        path:'/sportrecoreded',
        name:'/SportRecoreded',
        component: () => import('@/views/record/sport_recoreded.vue')
      },
      
  ]
  },
  {
    path:'/baseinfoedit',
    name:'/BaseInfoEdit',
    component: () => import('@/views/home/baseinfo_edit.vue')
  },
  {
    path: '/recheight',
    name: 'RecHeight',
    component: () => import('@/views/record/rec_height.vue')
  },
  {
    path: '/recweight',
    name: 'RecWeight',
    component: () => import('@/views/record/rec_weight.vue')
  },
  {
    path: '/search',
    name: 'Search',
    component: () => import('@/views/record/search.vue')
  },
  {
    path:'/recfood',
    name:'/RecFood',
    component: () => import('@/views/record/rec_food.vue')
  },
  {
    path:'/recsport',
    name:'/RecSport',
    component: () => import('@/views/record/rec_sport.vue')
  },
  {
    path:'/evaluate',
    name:'/Evaluate',
    component: () => import('@/views/home/evaluate.vue')
  },
  {
    path:'/checkevaluation',
    name:'/CheckEvaluation',
    component: () => import('@/views/home/check_evaluation.vue')
  },
  {
    path:'/recommends',
    name:'/Recommends',
    component: () => import('@/views/home/recommends.vue')
  },

]

const router = new VueRouter({
  routes
})
router.beforeEach((to, from, next) => {
  const token = "sessionStorage.getItem('userId')"
  const whitePath = ['/login']
  if (!token && !whitePath.includes(to.path)) {
    next('/login')
  } else {
    next()
  }
})
export default router